package io.renren.modules.study.controller;

import io.renren.common.annotation.Login;
import io.renren.common.config.ListPageUtils;
import io.renren.common.utils.R;
import io.renren.modules.study.entity.Course;
import io.renren.modules.study.entity.CourseComment;
import io.renren.modules.study.entity.PcPageBean;
import io.renren.modules.study.service.CourseService;
import io.renren.modules.study.service.MyCourseService;
import io.renren.modules.sys.dto.CollectDto;
import io.renren.modules.sys.service.TokenService;
import io.renren.modules.sys.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/course")
@Api(tags = "Pc课程")
public class PcCourseController {
    @Autowired
    CourseService courseService;

    @Autowired
    UserService userService;

    @Autowired
    TokenService tokenService;

    /**
     * Pc端用课程id查出课程评论
     */
    @PostMapping("getCourseCommentByCourseIdPc")
    @ApiOperation("查询课程评论")
    public R getCourseCommentByCourseIdPc(@ApiIgnore @RequestBody Map<String, Object> params) {
        PcPageBean<CourseComment> commentList = courseService.getCourseCommentByCourseIdPc(params);
        List bufferList = commentList.getList();
        for(int i = 0;i<bufferList.size();i++){
            CourseComment c =(CourseComment) bufferList.get(i);
            c.setContent(new String(c.getContentB()));
            c.setUserName(new String(c.getUserNameB()));
        }
        return R.ok().put("commentList", commentList);
    }
    /**
     * 查询课程同时带出老师名字
     */
    @PostMapping("getCourseAndTeacherName")
    @ApiOperation("查询课程和讲师名字")
    public R getCourseAndTeacherName(@ApiIgnore @RequestBody Map<String, Object> params) {
        PcPageBean<Course> courseList = courseService.getCourseAndTeacherName(params);
        return R.ok().put("courseList", courseList);
    }

    /**
     * Pc端一次性查出全部课程
     */
    @PostMapping("getAllCourseByOnce")
    @ApiOperation("查询全部课程和讲师名字")
    public R getAllCourseByOnce(@ApiIgnore @RequestBody Map<String, Object> params) {
        PcPageBean<Course> courseList = courseService.getAllCourseByOnce(params);
        return R.ok().put("courseList", courseList);
    }

    /**
     * Pc端根据title进行课程模糊查询
     */
    @PostMapping("pcGetCourseByTitleLike")
    @ApiOperation("模糊查询课程和讲师名字")
    public R pcGetCourseByTitleLike(@RequestBody Map params){
        PcPageBean<Course> course =courseService.pcGetCourseByTitleLike(params);
        return R.ok().put("course",course);
    }

    @PostMapping("pcGetMyCollectionCouseList")
    @Login
    @ApiOperation("查看我的收藏")
    public R pcGetMyCollectionCouseList(@RequestBody Map<String, Object> params) {
        PcPageBean<Course> courseList = courseService.pcGetMyCollectionCouseList(params);
        return R.ok().put("data", courseList);
    }

    @PostMapping("pcGetMyLearnCouseList")
    @Login
    @ApiOperation("查看我的收藏")
    public R pcGetMyLearnCouseList(@RequestBody Map<String, Object> params) {
        PcPageBean<Course> courseList = courseService.pcGetMyLearnCouseList(params);
        return R.ok().put("data", courseList);
    }

    @PostMapping("pcGetCourseCommentByUserId")
    @Login
    @ApiOperation("查看用户评论")
    public R pcGetCourseCommentByUserId(@RequestBody Map<String, Object> params) {
        PcPageBean<CourseComment> courseCommentList = courseService.pcGetCourseCommentByUserId(params);
        List bufferList = courseCommentList.getList();
        for(int i = 0;i<bufferList.size();i++){
            CourseComment c =(CourseComment) bufferList.get(i);
            c.setContent(new String(c.getContentB()));
            c.setUserName(new String(c.getUserNameB()));
        }
        return R.ok().put("data", courseCommentList);
    }
}
